GBML manual / Drawing

draw_self

Draws this instance using its own sprite/frame/angle/scale/flip/depth fields, exactly the way default drawing already would - callable from inside a custom Draw event to keep the default appearance while adding extra draw_sprite/draw_text calls around it. Inside a Draw GUI event it draws on the screen instead, with x and y read as a place on the screen.

Syntax

draw_self()

Returns

Nothing.

Description

Draws this instance exactly the way default drawing already would - its own sprite at its own frame, angle, xscale/yscale, flip_x/flip_y and depth. An object with no Draw event gets this for free, automatically, every frame. The moment you add a Draw event, that automatic drawing turns off for this object - defining Draw means "I am taking over drawing this instance myself." draw_self is how you get the normal look back from inside it, so adding one extra sprite or a line of floating text does not lose the instance's own default appearance along with it.

Called from a Draw GUI event it draws on the screen instead of in the room: the instance's x and y are then read as a place on the screen, counted from its top-left pixel. (Most objects that draw a HUD keep their own HUD picture and use draw_sprite there.)

Example

draw_self();
draw_text(x, y - 20, "!");

Keeps the instance drawn exactly as normal, then adds a floating ! above it - an alert marker, without giving up the default sprite to get it.

On the GBA

Default drawing is gated on whether an object defines a Draw event: an object with no Draw event of its own gets default_draw's automatic pass every frame; an object that defines one does not, and never did again once it does (gbml::object_def::default_draw, engine/include/gbml/object.h, is simply left null for that object's row - gbml/codegen.js only binds it for an object with no Draw event). So calling draw_self inside a Draw event is not a harmless extra draw of an already-drawn sprite - it is the only thing standing between that object and drawing nothing at all.

See also: draw_sprite